<?php

class Application_Form_TicketAnlegenForm extends Zend_Form
{
	
	protected $_dauer;
	protected $_name;
	protected $_preis;
	protected $_verfuegbar_ab;
	protected $_verfuegbar_bis;
	protected $_gueltig_ab;
	protected $_gueltig_bis;
	protected $_ticketart;
	protected $_tage;
 
public function __construct($options = null,$dauer = '',$name= '' ,$preis= '',$verfuegbar_ab = '',$verfuegbar_bis = '',$gueltig_ab = '',$gueltig_bis = '',$ticketart = '', $tage = '')
    {
		$this->_dauer= $dauer;
    	$this->_name = $name;
        $this->_preis= $preis;
    	$this->_verfuegbar_ab = $verfuegbar_ab;
    	$this->_verfuegbar_bis = $verfuegbar_bis;
    	$this->_gueltig_ab = $gueltig_ab;
    	$this->_gueltig_bis = $gueltig_bis;
    	$this->_ticketart = $ticketart;
    	$this->_tage = $tage;
        parent::__construct($options);
    }
	public function init()
    {
        /* Form Elements & Other Definitions Here ... */
    $decorator = new My_Decorator_SimpleInput();
    	
    	$this->setName('Ticket erstellen');
        // Set the method for the display form to POST
        $this->setMethod('post');

        // Dauer
        $dauer  = new Zend_Form_Element('dauer', array(
        'label'      => 'Dauer in Tagen:',
        'value'      => $this->_dauer,
        'decorators' => array($decorator),
        'filters'    => array('StringTrim')
    	));
    	$dauer
    		->clearDecorators()
    		->addDecorator($decorator)
    		->addDecorator('Errors');
        
        // Ticketname
        $name  = new Zend_Form_Element('name', array(
        'label'      => 'Ticketname:',
        'value'      => $this->_name,
        'decorators' => array($decorator),
        'filters'    => array('StringTrim')
    	));
    	$name
    		->setRequired()
    		->addErrorMessage('Das Feld darf nicht leer sein')
    		->clearDecorators()
    		->addDecorator($decorator)
    		->addDecorator('Errors');
        
        // Preis
        $preis  = new Zend_Form_Element('preis', array(
        'label'      => 'Preis in Euro:',
        'value'      => $this->_preis,
        'required'	 => true,
        'decorators' => array($decorator),
        'filters'    => array('StringTrim')
    	));
    	$preis
    		->setRequired()
    		->addErrorMessage('Das Feld darf nicht leer sein')
    		->clearDecorators()
    		->addDecorator($decorator)
    		->addDecorator('Errors');
        
        // Ticketart
        $ticketart = new Zend_Form_Element_Select('ticketart', array(
        'label'		=> 'Ticketart:',
        'value'		=> $this->_ticketart,
        'required'	=> true,
        'multiOptions' => array( 1 => 'fester Zeitraum', 0 => 'feste Dauer'),
        'onchange'	=> 'umschalten()'
        ));
        $ticketart
    		->addDecorator('Errors');
       
       // verfügbar ab
        $verfuegbar_ab  = new Zend_Form_Element('verfuegbar_ab', array(
        'label'      => 'verfügbar ab:',
        'value'      => $this->_verfuegbar_ab,
        'required'	 => true,
        'decorators' => array($decorator),
        'filters'    => array('StringTrim')
    	));
    	$verfuegbar_ab
    		->setRequired()
    		->addErrorMessage('Das Feld darf nicht leer sein')
    		->clearDecorators()
    		->addDecorator($decorator)
    		->addDecorator('Errors');
        
        // verfügbar bis
        $verfuegbar_bis  = new Zend_Form_Element('verfuegbar_bis', array(
        'label'      => 'verfügbar bis:',
        'value'      => $this->_verfuegbar_bis,
        'required'	 => true,
        'decorators' => array($decorator),
        'filters'    => array('StringTrim')
    	));
    	$verfuegbar_bis
    		->setRequired()
    		->addErrorMessage('Das Feld darf nicht leer sein')
    		->clearDecorators()
    		->addDecorator($decorator)
    		->addDecorator('Errors');
        
        // gültig ab
        $gueltig_ab  = new Zend_Form_Element('gueltig_ab', array(
        'label'      => 'gültig ab:',
        'value'      => $this->_gueltig_ab,
        'required'	 => true,
        'decorators' => array($decorator),
        'filters'    => array('StringTrim')
    	));
    	$gueltig_ab
    		->setRequired()
    		->addErrorMessage('Das Feld darf nicht leer sein')
    		->clearDecorators()
    		->addDecorator($decorator)
    		->addDecorator('Errors');
        
        // gültig bis
        $gueltig_bis  = new Zend_Form_Element('gueltig_bis', array(
        'label'      => 'gültig bis:',
        'value'      => $this->_gueltig_bis,
        'required'	 => true,
        'decorators' => array($decorator),
        'filters'    => array('StringTrim')
    	));
    	$gueltig_bis
    		->setRequired()
    		->addErrorMessage('Das Feld darf nicht leer sein')
    		->clearDecorators()
    		->addDecorator($decorator)
    		->addDecorator('Errors');
        
        $tage = new Zend_Form_Element_MultiCheckbox('tage', array(
    	'label'		=> 'Wochentage:',
        'multiOptions' => array(
    
            '1'	=> 'Montag',
        	'2'	=> 'Dienstag',
        	'3'	=> 'Mittwoch',
        	'4'	=> 'Donnerstag',
        	'5'	=> 'Freitag',
        	'6'	=>	'Samstag',
        	'7'	=>	'Sonntag')
        ));//$tage->getValue() holt die gecheckten Werte als array
        $tage
    		->addErrorMessage('Fehler bei den Wochentagen')
    		->addDecorator('Errors');
		
		$form = new Zend_Form();
		$this->addElements(array($name, $preis, $verfuegbar_ab, $verfuegbar_bis, $gueltig_ab, $gueltig_bis, $ticketart, $dauer, $tage));
		// Submit button
        $this->addElement('submit', 'submit', array('label' => 'Speichern', 'class' => 'button'));
    }
}


class My_Decorator_SimpleInput extends Zend_Form_Decorator_Abstract
    {
        protected $_format = '<label for="%s">%s</label><input id="%s" name="%s" type="text" value="%s"/>';
     
        public function render($content)
        {
            $element = $this->getElement();
            $name    = htmlentities($element->getFullyQualifiedName());
            $label   = htmlentities($element->getLabel());
            $id      = htmlentities($element->getId());
            $value   = htmlentities($element->getValue());
     
            $markup  = sprintf($this->_format, $name, $label, $id, $name, $value);
            return $markup;
        }
    }